package com.goods.controller.business;

import com.goods.business.service.BizSupplierService;
import com.goods.common.model.business.BizProductCategory;
import com.goods.common.model.business.BizSupplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductCategoryTreeNodeVO;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/business/supplier")
public class BizSupplierController {

    @Autowired
    private BizSupplierService bizSupplierService;

    @GetMapping("/findSupplierList")
    public ResponseBean findSupplierList(@RequestParam Map<String, Object> paramMap){
        PageVO<SupplierVO> supplierPageVO = bizSupplierService.findSupplierListByMap(paramMap);
        return ResponseBean.success(supplierPageVO);
    }

    @GetMapping("/findAll")
    public ResponseBean findAll(){
        List<SupplierVO> supplierVOS = bizSupplierService.findAll();
        return ResponseBean.success(supplierVOS);
    }
    @PostMapping("/add")
    public ResponseBean addSupplier(@RequestBody SupplierVO supplierVO){
        bizSupplierService.addSupplier(supplierVO);
        return ResponseBean.success();
    }

    @GetMapping("/edit/{id}")
    public ResponseBean editSupplier(@PathVariable Integer id) {
        SupplierVO supplierVO = bizSupplierService.getSupplierVo(id);
        return ResponseBean.success(supplierVO);
    }

    @PutMapping("/update/{id}")
    public ResponseBean updateSupplier(@PathVariable Integer id, @RequestBody SupplierVO supplierVO) {
        bizSupplierService.updateBizSupplier(id,supplierVO);
        return ResponseBean.success();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseBean deleteSupplier(@PathVariable Integer id){
        bizSupplierService.deleteSupplierById(id);
        return ResponseBean.success();
    }

}
